package com.jn.tools;

import java.util.HashMap;
import java.util.Map;

import com.jn.entity.EntityQuery;

public class DataSearchTools {
	
	public final static Map<String,String> operationMap = new HashMap<String,String>();
	
	static {
		operationMap.put("eq", "=");//等于 equal
		operationMap.put("neq", "!=");//不等于 not equal
		operationMap.put("gt", ">");//大于 greater than
		operationMap.put("lt", "<");//小于 less than
		operationMap.put("gteq", ">=");//大于等于 greater than equal
		operationMap.put("lteq", "<=");//小于等于 less than equal
		operationMap.put("like", "like");//包含 like
		operationMap.put("pl", "like");//前包含 pre like
		operationMap.put("bl", "like");//后包含 back like
	}
	
	public static EntityQuery operationSymbol(String key, String operation, Object val){
		String operationStr = operationMap.get(operation);
		String valStr = "";
		
		if(operation.equals("like")){
			valStr = "%" + val + "%";
		}else
		if(operation.equals("pl")){
			valStr = "%" + val;
		}else
		if(operation.equals("bl")){
			valStr = val + "%";
		}
		
		return new EntityQuery(key,operationStr,valStr.equals("") ? val : valStr);
	}
	
}
